﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Vmago.Models;
using Vmago.Models.DBML;
using Vmago;
using System.Xml;
using System.Collections;
using System.Web.UI;

namespace Vmago.Controllers
{
    public class CityController : ControllerBase
    {
        #region Global：变量

        private ICategory _cityMasterCategory;
        private ICity _city;
        private IShopDetails _shopDetails;
        private IRecShop _recShop;
        private IShopComment _shopComment;
        private IShopSearch _shopSearch;
        private IShopProduct _shopProduct;
        private IShopVoucher _shopVoucher;
        int CityId = 0;
        //int testNum = 0;

        /// <summary>TblDataContext对象</summary>
        private TblDataContext m_dcTbl = new TblDataContext();

        private ViewDataContext m_dcView = new ViewDataContext();

        #endregion

        #region Global：构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        public CityController()
        {
            _cityMasterCategory = new RepositoryCategory();
            _city = new RepositoryCity();
            _shopDetails = new RepositoryShopDetails();
            _recShop = new RepositoryRecShop();
            _shopComment = new RepositoryShopComment();
            _shopSearch = new RepositoryShopSearch();
            _shopProduct = new RepositoryShopProduct();
            _shopVoucher = new RepositoryShopVoucher();
        }

        #endregion

        #region CityDetail：页面初始化

        /// <summary>页面初始化</summary>
        public ActionResult CityDetail(string id)
        {
            Int32 id_ = 0;
            Int32.TryParse(id, out id_);

            //获得所有大分类
            List<tbl_class> oClasss = (from p in m_dcTbl.tbl_class
                                       select p).ToList();

            //初始化商店
            List<List<vw_recShop>> oRecShopss = new List<List<vw_recShop>>();

            //遍历大分类，查询所有商店
            foreach (tbl_class oClass in oClasss)
            {
                List<vw_recShop> oRecShops = m_dcView.prc_shopRecShop(id_, oClass.classID, null, null, null).ToList();
                oRecShopss.Add(oRecShops);
            }

            ViewData["Class"] = oClasss;
            ViewData["RecShop"] = oRecShopss;
            ViewData["CityID"] = id;

            return View("CityDetail");
        }

        #endregion

        #region CityIfram：...

        public ActionResult CityIfram(int Class, int Category, int Suburb)
        {
            int category = 0;
            if (Category == 0)
            {
                category = 2;
            }
            ViewData["ClassID"] = Class;
            ViewData["Category"] = category;
            ViewData["Sbuburb"] = Suburb;
            return View("CityIfram");
        }

        #endregion

        #region Index：页面初始化

        public ActionResult Index()
        {
            // Add action logic here
            throw new NotImplementedException();
        }

        #endregion

        #region Trademark：Init

        /// <summary>
        /// 根据传进的商户的ID进行商户信息查询.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Trademark(String id)
        {
            try
            {
                Int32 id_ = 0;
                Int32.TryParse(id, out id_);

                ViewData["Position"] = _shopDetails.getShopPosition(id).First();

                ViewData["SubShops"] = _shopDetails.getShopSubShop(id);

                ViewData["Comment"] = _shopComment.getShopComment(id_);

                ViewData["RecShop"] = _recShop.getRelatedShop(id_, 10, 1);

                Trademark_GetShop(id_);

                Trademark_GetShopInfo(id_);

                Trademark_GetShopImage(id_);

                Trademark_GetShopPosition(id_);
            }
            catch (Exception ex)
            {
                //当程序异常时的处理
                Console.WriteLine("CityController:Trademark" + ex);
            }

            return View();
        }

        /// <summary>
        /// 查询商铺信息
        /// </summary>
        /// <param name="intShopID"></param>
        private void Trademark_GetShop(Int32 intShopID)
        {
            //获得tbl_shop对象
            IEnumerable<tbl_shop> oShops = from o in m_dcTbl.tbl_shop
                                           where o.shopID == intShopID
                                           select o;

            if (oShops.Count() == 0)
            {
                ViewData["Name"] = String.Empty;
                ViewData["Address"] = String.Empty;
                ViewData["Descrition"] = String.Empty;
            }
            else
            {
                ViewData["Name"] = oShops.First().name;
                ViewData["Address"] = oShops.First().address;
                ViewData["Descrition"] = oShops.First().description;
            }
        }

        /// <summary>
        /// 查询商铺位置
        /// </summary>
        /// <param name="intShopID"></param>
        private void Trademark_GetShopPosition(Int32 intShopID)
        {
            IEnumerable<tbl_shopPosition> oPosition = from p in m_dcTbl.tbl_shopPosition
                                                      from s in m_dcTbl.tbl_shop
                                                      where p.positionID == s.positionID
                                                      where s.shopID == intShopID
                                                      select p;
            if (oPosition.Count() == 0)
            {
                ViewData["GPS"] = oPosition.First().address;
            }
            else
            {
                ViewData["GPS"] = oPosition.First().address;
            }
        }

        /// <summary>
        /// 查询商铺详细信息
        /// </summary>
        /// <param name="intShopID"></param>
        private void Trademark_GetShopInfo(Int32 intShopID)
        {
            //获得tbl_shopCategoryMappingValue对象集合
            IEnumerable<tbl_shopCategoryMappingValue> oValues = from o in m_dcTbl.tbl_shopCategoryMappingValue
                                                                where o.shopID == intShopID
                                                                select o;
            //赋值ViewData
            foreach (tbl_shopCategoryMappingValue oValue in oValues)
            {
                ViewData["V" + oValue.itemID.ToString("D2")] = oValue.value;
            }
        }

        /// <summary>
        /// 查询商铺Logo
        /// </summary>
        /// <param name="intShopID"></param>
        private void Trademark_GetShopImage(Int32 intShopID)
        {
            IEnumerable<tbl_shopImage> oImages = from o in m_dcTbl.tbl_shopImage
                                                 where o.shopID == intShopID
                                                 select o;

            if (oImages.Count() == 0)
            {
                ViewData["Logo"] = String.Empty;
                ViewData["LogoAlt"] = String.Empty;
            }
            else
            {
                ViewData["Logo"] = oImages.First().filename;
                ViewData["LogoAlt"] = oImages.First().description;
            }
        }

        #endregion

        #region Trademark：提交评论

        /// <summary>
        /// 提交评论
        /// </summary>
        /// <param name="id"></param>
        /// <param name="BSS_Comment"></param>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Trademark(String id, String BSS_Comment)
        {
            Int32 id_ = 0;
            Int32.TryParse(id, out id_);

            if (!String.IsNullOrEmpty(BSS_Comment.Trim()))
            {
                String ShopName = _shopDetails.getShopDetails(id).First(o => o.itemName.Equals("中文名称")).value;

                _shopComment.insertShopComment(id_, ShopName, BSS_Comment, User.Identity.Name, Request.UserHostAddress, 0, 1, 0, 0);
            }

            return Trademark(id);
        }

        #endregion

        #region Shared/CityInfoMenu：查询

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Shared_CityInfoMenu_Query(String Class, String ShopCategory, String GeoSuburb, String CityID)
        {
            Int32 intClass = 0;
            Int32 intShopCategory = 0;
            Int32 intGeoSuburb = 0;
            Int32 intCityID = 0;

            Int32.TryParse(Class, out intClass);
            Int32.TryParse(ShopCategory, out intShopCategory);
            Int32.TryParse(GeoSuburb, out intGeoSuburb);
            Int32.TryParse(CityID, out intCityID);

            //商店
            List<List<vw_recShop>> oRecShopss = new List<List<vw_recShop>>();
            IEnumerable<vw_recShop> shop;
            //大分类
            List<Int32> ClassIds = new List<Int32>();
            List<Int32> ShopIds = new List<Int32>();

            if (String.IsNullOrEmpty(Class))
            {

                ClassIds = (from p in m_dcTbl.tbl_class
                            select p.classID).ToList();

                if (String.IsNullOrEmpty(ShopCategory))
                {
                    shop = from a in m_dcView.vw_recShop
                           where a.city == intCityID
                           && ClassIds.Contains(a.category)
                           select a;
                }
                else
                {
                    ShopIds = (from s in m_dcTbl.tbl_shopCategoryMapping
                               from g in m_dcTbl.tbl_shopCategory
                               where s.categoryID == g.categoryID
                               && (g.categoryID == intShopCategory || g.parentID == intShopCategory)
                               select s.shopID).ToList();

                    shop = from a in m_dcView.vw_recShop
                           where a.city == intCityID
                           && ClassIds.Contains(a.category)
                           && ShopIds.Contains(a.shopID)
                           select a;
                }

            }
            else
            {
                ClassIds = (from p in m_dcTbl.tbl_class
                            where p.classID == intClass
                            select p.classID).ToList();

                if (String.IsNullOrEmpty(ShopCategory))
                {
                    shop = from a in m_dcView.vw_recShop
                           where a.city == intCityID
                           && ClassIds.Contains(a.category)
                           select a;
                }
                else
                {
                    ShopIds = (from s in m_dcTbl.tbl_shopCategoryMapping
                               from g in m_dcTbl.tbl_shopCategory
                               where s.categoryID == g.categoryID
                               && (g.categoryID == intShopCategory || g.parentID == intShopCategory)
                               select s.shopID).ToList();

                    shop = from a in m_dcView.vw_recShop
                           where a.city == intCityID
                           && ClassIds.Contains(a.category)
                           && ShopIds.Contains(a.shopID)
                           select a;
                }
            }

            List<tbl_class> rClasss = new List<tbl_class>();
            rClasss.Add(new tbl_class { className = "查询", classID = 0 });

            if (shop != null)
            {
                oRecShopss.Add(shop.ToList());
            }

            ViewData["Class"] = rClasss;
            ViewData["RecShop"] = oRecShopss;
            ViewData["CityID"] = CityID;

            return View("CityDetail");
        }

        #endregion

        #region Shared/CityInfoMenu： 搜索

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Shared_CityInfoMenu_Search(String SearchKey, String CityID)
        {
            return CityDetail(CityID);
        }

        #endregion

        #region 公有方法：给页眉上的3个下拉框赋值

        /// <summary>
        /// 给页眉上的3个下拉框赋值
        /// </summary>
        /// <param name="classID"></param>
        [Authorize]
        [AcceptVerbs(HttpVerbs.Post)]
        public void CityMasterViewData(int classID)
        {
            ViewData["Class"] = new SelectList(_cityMasterCategory.getClass(), "classID", "className");
            ViewData["Category"] = new SelectList(_cityMasterCategory.getSubCategoryCityMaster(classID), "categoryID", "categoryName");
            ViewData["Suburb"] = new SelectList(_city.getSuburb(21, 21), "suburbID", "suburbName");
        }

        #endregion

        #region 公有方法：得到商户中展示的图片

        /// <summary>
        /// 得到商户中展示的图片
        /// </summary>
        /// <param name="id"></param>
        public void getShopImage(string id)
        {
            //方法数据初始化
            string imgaUrl = null;
            string shopid = id;

            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            objectlist.Clear();
            try
            {
                //通过调用GetShopProductList方法来得到后台的数据信息
                objectlist = GetShopProductList(shopid);
                //通过循环将得到的数据填入到字段中,并将其添加到OBJ中
                for (int i = 0; i < objectlist.Count; i++)
                {
                    imgaUrl = objectlist[i].ToString();
                    obj.Add(imgaUrl);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:getTrademark" + ex);
                obj.Add("nothing");
            }
            //调用RenderJSON来将数据传到前台显示在页面上
            RenderJSON(obj);
        }

        #endregion

        #region 公有方法：通过数据库查询出相应的数据

        /// <summary>
        /// 通过数据库查询出相应的数据
        /// </summary>
        /// <param name="ShopID"></param>
        /// <returns></returns>
        public List<object> GetShopProductList(string ShopID)
        {
            List<object> lobj = new List<object>();
            try
            {
                //通过调用GetShopProduct方法来得到相应的数据
                IEnumerable<ShopProduct> c = GetShopProduct(ShopID);
                IEnumerable<ShopProductImage> cImg = GetShopProductImg(ShopID);
                // ShopProduct r = c.First();
                string s = null;
                int cc = c.Count();
                //通过循环来将已知的数据填到字段中并加载到BOJ中
                for (int i = 0; i < cImg.Count(); i++)
                {
                    //ShopProduct rr = c.ElementAt(i);
                    //int productID = rr.productID;
                    //调用GetShopProductImg后台方法来得到IMG的NAME

                    ShopProductImage rImg = cImg.ElementAt(i);
                    s = rImg.filename + "|" + rImg.shopID + "|" + rImg.description;
                    lobj.Add(s);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:getTrademark" + ex);
                lobj.Add(" ");
            }
            //返回数据给调用此方法的地方

            return lobj;
        }

        #endregion

        #region 公有方法：得到优惠信息

        /// <summary>
        /// 得到优惠信息
        /// </summary>
        /// <param name="id"></param>
        public void getShopVoucher(string id)
        {
            string imgaUrl = null;
            string shopid = id;

            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            objectlist.Clear();
            try
            {
                //调用GetShopProductList得到相应的所有数据
                objectlist = GetShopProductList(shopid);
                for (int i = 0; i < objectlist.Count; i++)
                {
                    imgaUrl = objectlist[i].ToString();
                    //此为默认加载的商户优惠信息
                    if (imgaUrl == "" || imgaUrl == null)
                    {
                        imgaUrl = "优惠信息的描述     |优惠信息的名字     |优惠信息的开始时间     |优惠信息的结束时间";
                    }
                    //将字段加到OBJ中
                    obj.Add(imgaUrl);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:getTrademark" + ex);
                obj.Add(" ");
            }
            //调用RenderJSON把得到的数据返回到前台页面中
            RenderJSON(obj);
        }

        #endregion

        #region 公有方法：连接getShopVoucher和后台数据查询接口的方法

        /// <summary>
        /// 连接getShopVoucher和后台数据查询接口的方法
        /// </summary>
        /// <param name="ShopID"></param>
        /// <returns></returns>
        public List<object> GetShopVoucherList(string ShopID)
        {
            List<object> lobj = new List<object>();
            try
            {
                //调用GetShopVouchert方法来得到商户的所有优惠信息
                IEnumerable<ShopVoucher> c = GetShopVouchert(ShopID);

                string s = null;
                int cc = c.Count();
                //通过循环将数据连接成一个字段
                for (int i = 0; i < c.Count(); i++)
                {
                    ShopVoucher rr = c.ElementAt(i);
                    s = rr.description + "|" + rr.voucherName + "|" + rr.startDate + "|" + rr.endDate;
                    //将连接好的字段加载到OBJ中
                    lobj.Add(s);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:getTrademark" + ex);
                lobj.Add(" ");
            }

            //返回给调用此方法的地方
            return lobj;
        }

        #endregion

        #region 调用数据库接口：得到Province数据内容的后台方法接口

        /// <summary>
        /// 得到Province数据内容的后台方法接口
        /// </summary>
        /// <param name="countryID"></param>
        /// <returns></returns>
        public IEnumerable<Province> getProvince(int countryID)
        {
            IEnumerable<Province> c = _city.getProvince(countryID);
            return c;
        }

        #endregion

        #region 调用数据库接口：得到City数据内容的后台方法接口

        /// <summary>
        /// 得到City数据内容的后台方法接口
        /// </summary>
        /// <param name="countryID"></param>
        /// <param name="ProvinceID"></param>
        /// <returns></returns>
        public IEnumerable<City> getProvince(int countryID, int ProvinceID)
        {
            IEnumerable<City> c = _city.getCity(countryID, ProvinceID);
            return c;
        }

        #endregion

        #region 调用数据库接口：得到Country数据内容的后台方法接口

        /// <summary>
        /// 得到Country数据内容的后台方法接口
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Country> getCountry()
        {
            IEnumerable<Country> c = _city.getCountry();
            return c;
        }

        #endregion

        #region 调用数据库接口：得到指定CITY数据内容的后台方法接口

        /// <summary>
        /// 得到指定CITY数据内容的后台方法接口
        /// </summary>
        /// <param name="CountryID"></param>
        /// <returns></returns>
        public IEnumerable<City> GetProvinceDetail(int CountryID)
        {
            IEnumerable<City> c = _city.getCity(CountryID, 1);
            return c;
        }

        #endregion

        #region 调用数据库接口：调用后台数据查询方法接口

        /// <summary>
        /// 调用后台数据查询方法接口
        /// </summary>
        /// <param name="ShopID"></param>
        /// <returns></returns>
        public IEnumerable<ShopDetail> GetShopDetails(string ShopID)
        {
            IEnumerable<ShopDetail> c = _shopDetails.getShopDetails(ShopID);
            return c;
        }

        #endregion

        #region 调用数据库接口：调用getShopProduct得到商户产品所有信息

        /// <summary>
        /// 调用getShopProduct得到商户产品所有信息
        /// </summary>
        /// <param name="ShopID"></param>
        /// <returns></returns>
        public IEnumerable<ShopProduct> GetShopProduct(string ShopID)
        {
            IEnumerable<ShopProduct> c = _shopProduct.getShopProduct(Convert.ToInt32(ShopID));
            return c;
        }

        #endregion

        #region 调用数据库接口：调用getShopProductImage得到商户所以图片信息

        /// <summary>
        /// 调用getShopProductImage得到商户所以图片信息
        /// </summary>
        /// <param name="ShopID"></param>
        /// <returns></returns>
        public IEnumerable<ShopProductImage> GetShopProductImg(string ShopID)
        {
            IEnumerable<ShopProductImage> c = _shopProduct.getShopProductImage(Convert.ToInt32(ShopID));
            return c;
        }

        #endregion

        #region 调用数据库接口：调用getShopVoucher得到商户所有优惠信息

        /// <summary>
        /// 调用getShopVoucher得到商户所有优惠信息
        /// </summary>
        /// <param name="ShopID"></param>
        /// <returns></returns>
        public IEnumerable<ShopVoucher> GetShopVouchert(string ShopID)
        {
            IEnumerable<ShopVoucher> c = _shopVoucher.getShopVoucher(Convert.ToInt32(ShopID));
            return c;
        }

        #endregion

        #region 得到此商户的子商户
        //得到此商户的子商户
        public void ShopSubShop(string id)
        {
            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            string s = "";
            objectlist.Clear();
            try
            {
                //通过调用GetShopSubShop方法来得到子商户的信息
                objectlist = GetShopSubShop(id);

                for (int i = 0; i < objectlist.Count; i++)
                {
                    //将数据添加到变量中
                    s = objectlist[i].ToString() + "|";

                }
                //将有数据的变量添加到OBJ中
                obj.Add(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:ShopSubShop" + ex);
                obj.Add(" ");
            }
            //调用RenderJSON方法来将数据返回到前台页面上
            RenderJSON(obj);
        }
        //此方法调用数据库接口方法查询数据,并将数据返回到调用此方法的地方
        public List<object> GetShopSubShop(string ShopID)
        {
            string s = "";

            List<object> obj = new List<object>();
            //通过调用GetShopSShop得到商户子商户的所有信息
            IEnumerable<ShopSubShop> c = GetShopSShop(ShopID);
            try
            {
                //通过循环来将得到的数据加载到变量中
                for (int i = 0; i < c.Count(); i++)
                {
                    ShopSubShop sss = c.ElementAt(i);
                    s += sss.subShopName + "|" + sss.subShopID + "|";

                }
                obj.Add(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:GetShopSubShop" + ex);
                obj.Add(" | | ");
            }
            //将有数据的OBJ返回给调用此方法的地方
            return obj;
        }
        //调用查询子商户的后台接口
        public IEnumerable<ShopSubShop> GetShopSShop(string ShopID)
        {
            IEnumerable<ShopSubShop> c = _shopDetails.getShopSubShop(ShopID);
            return c;
        }
        #endregion

        #region 得到各个子店的具体信息查询,包括经纬度
        //得到各个子店的具体信息查询,包括经纬度
        public void SubShopSublanlgn(string id)
        {
            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            string s = "";
            objectlist.Clear();
            try
            {
                //调用GetSubShopSublanlgn来得到经纬度数据
                objectlist = GetSubShopSublanlgn(id);
                //通过循环将数据加载到变量中
                for (int i = 0; i < objectlist.Count; i++)
                {
                    s = objectlist[i].ToString() + "|";

                }
                //将得到的变量加载到OBJ中
                obj.Add(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:SubShopSublanlgn" + ex);
                obj.Add(" | ");
            }
            //通过调用RenderJSON将数据传到前台并显示出来
            RenderJSON(obj);
        }

        //查询子商户的经纬度坐标
        public List<object> GetSubShopSublanlgn(string ShopID)
        {
            string[] s = null;
            s = ShopID.Split(',');
            List<object> obj = new List<object>();
            //得到商户ID
            int shopID = Convert.ToInt32(s[0]);
            //得到城市ID
            int cityID = Convert.ToInt32(s[1]);
            //得到CATEGORYID
            int categoryID = Convert.ToInt32(s[2]);

            try
            {
                double lat;
                double lng;
                //通过调用后台数据查询方法getRecShopSubShop来得到子商户的信息
                List<RecShop> c = _recShop.getRecShopSubShop(cityID, categoryID, shopID);
                //通过循环来把子商户的数据加载到变量中
                foreach (RecShop r in c)
                {
                    lat = Convert.ToDouble(r.latitude);
                    lng = Convert.ToDouble(r.longitude);

                    string result = lat.ToString() + "|" + lng.ToString();
                    obj.Add(result);

                }
                //将数据加载到OBJ中
                obj.Add(s);

            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:GetSubShopSublanlgn" + ex);
                obj.Add(" | ");
            }
            //将数据返回给调用方法的地方
            return obj;
        }
        #endregion

        #region 商户全部图片浏览
        //商户全部图片浏览
        public ActionResult MoreCityImg(string id)
        {
            //得到CITYID
            int cityID = Convert.ToInt32(Request["CityID"].ToString());
            ViewData["CityID"] = cityID;
            UtilController uc = new UtilController();
            //得到CITYNAME
            string CityName = uc.getCityName(cityID.ToString());
            //得到CATEGORYID
            int categoryID = Convert.ToInt32(Request["CategoryID"].ToString());
            //根据不同的CATEGORYID值给相应的标签填充值
            if (categoryID == 1)
            {
                ViewData["CategoryName"] = "餐饮";
                ViewData["categoryID"] = "1";
            }
            if (categoryID == 2)
            {
                ViewData["CategoryName"] = "住宿";
                ViewData["categoryID"] = "2";
            }
            if (categoryID == 3)
            {
                ViewData["CategoryName"] = "购物";
                ViewData["categoryID"] = "3";
            }
            if (categoryID == 4)
            {
                ViewData["CategoryName"] = "游玩";
                ViewData["categoryID"] = "4";
            }
            if (CityName != "" || CityName != null)
            {
                ViewData["CityName"] = CityName;
            }
            ViewData["CountryName"] = "日本";

            //string[] s = obj[0].ToString().Split('|');

            //ViewData["ShopName"] = s[1];

            CityMasterViewData(1);
            return View();
        }

        #endregion

        #region 景观页面
        public ActionResult Prospect()
        {
            CityMasterViewData(1);
            return View();
        }
        #endregion

        #region 酒店页面
        public ActionResult Cabaret()
        {
            CityMasterViewData(1);
            return View();
        }
        #endregion

        #region 新商户页
        public ActionResult NewTrademark()
        {
            CityMasterViewData(1);
            return View();
        }
        #endregion

        #region 第二页联动效果
        //第二页联动效果
        public void ChangeIdCityDetail(string id)
        {

            //string ss = null;
            CityId = Convert.ToInt32(id);
            List<object> objectlist = new List<object>();

            try
            {
                ////通过调用GetAllList来得到相应的数据
                //IList<System.Web.Mvc.ListItem> list = GetAllList(CityId);

                //objectlist.Clear();
                ////通过循环来将数据加载到变量中并加到OBJ中
                //for (int i = 0; i < list.Count; i++)
                //{
                //    ss = list[i].Text + "|" + list[i].Value;
                //    objectlist.Add(ss);
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:GetSubShopSublanlgn" + ex);
                objectlist.Add(" | ");
            }
            //通过调用RenderJSON将数据调到前台然后在页面上显示
            RenderJSON(objectlist);

            //   return View();
        }
        //调用数据库后台的接口方法
        //public IList<System.Web.Mvc.ListItem> GetAllList(int classID)
        //{
        //    SelectList selectlist = new SelectList(_cityMasterCategory.getSubCategoryCityMaster(classID), "categoryID", "categoryName");
        //    IList<System.Web.Mvc.ListItem> list = selectlist.GetListItems();
        //    return list;
        //}
        #endregion

        #region 测试用全局变量

        public int testApplication(int countryid)
        {
            IEnumerable<Country> testcountry = getCountry(countryid);

            if (testcountry.Count() != 0)
            {
                int testcountryID = testcountry.First().countryID;
                return testcountryID;
            }
            else
            {
                int testcountryID = 0;
                return testcountryID;
            }
        }
        #endregion

        #region Country数据库接口方法
        //Country数据库接口方法
        public IEnumerable<Country> getCountry(int countryid)
        {
            IEnumerable<Country> c = _city.getCountry(countryid);
            return c;
        }
        #endregion

        #region 第二页右边栏中初始化数据接口
        //右边栏中初始化数据
        private string CityID;
        private List<object> objSetMark;

        #region TAB商户信息加载
        //TAB商户信息加载
        public void RightColumnInterface(string id)
        {

            string[] idNum = id.Split(',');

            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            string s = "";
            //得到categoryID
            int categoryID = Convert.ToInt32(idNum[2]);
            //得到CityID
            CityID = idNum[0];
            //得到页数,初始化为1
            int page = Convert.ToInt32(idNum[1]);

            try
            {
                objectlist.Clear();
                //调用GetRecShop来进行数据查询并将数据返回出来
                objectlist = GetRecShop(CityID, categoryID, page);
                if (objectlist.Count != 0)
                {
                    //通过循环来将得到的数据加到变量中并加载到OBJ中
                    for (int i = 0; i < objectlist.Count; i++)
                    {
                        s = objectlist[i].ToString() + "|";
                        obj.Add(s);
                    }
                    obj.Add(idNum[2]);
                    objSetMark = obj;
                }
                else
                {
                    string initCityLan = getCityinitLan(CityID);

                    obj.Add("nonintmessage|" + initCityLan);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController: RightColumnInterface:" + ex);
                obj.Add("nonintmessage");
                objSetMark = obj;
            }

            ViewData["CityID"] = CityID;
            //调用RenderJSON将数据返回到前台
            RenderJSON(obj);
        }
        #endregion

        #region 得到并返回一共的页数
        //得到并返回一共的页数
        public void RightPageNum(string id)
        {

            string[] pageID = id.Split(',');
            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            string s = "";
            try
            {
                objectlist.Clear();
                //通过调用GetRecShop来得到相应的数据,并将数据加载到变量中,再加载到OBJ中
                objectlist = GetRecShop(pageID[0], Convert.ToInt32(pageID[1]));
                s = objectlist[0].ToString();
                obj.Add(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController: RightPageNum:" + ex);
                obj.Add(" |");

            }

            //调用RenderJSON将数据返回到前台页面上了
            RenderJSON(obj);
        }
        #endregion

        #region 点击TAB之后得到相对应Category
        //点击TAB之后得到相对应Category
        public void ClickColumnInterface(string id)
        {
            //将传入的数据分割开来
            string[] CategoryID = id.Split(',');
            //得到categoryid
            int categoryid = Convert.ToInt32(CategoryID[0]);

            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            string s = "";
            try
            {
                objectlist.Clear();
                //得到cityid
                string cityid = CategoryID[1];
                //通过调用GetRecShop来得到相应的数据
                objectlist = GetRecShop(cityid, categoryid, Convert.ToInt32(CategoryID[2]));
                //通过循环来将数据加到变量中,并加载到OBJ中
                for (int i = 0; i < objectlist.Count; i++)
                {
                    s = objectlist[i].ToString() + "|";
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController: ClickColumnInterface:" + ex);
                obj.Add(" |");

            }
            //通过调用RenderJSON方法来将数据传到前台
            RenderJSON(obj);
        }
        #endregion

        #region 点击了分页后查询相对应的数据
        //点击了分页后查询相对应的数据
        public void ClickPage(string id)
        {

            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            string s = "";
            try
            {
                objectlist.Clear();
                //调用GetRecShop得到相应的数据
                objectlist = GetRecShop(id);
                //通过循环来将数据放到变量中并加载到OBJ中
                for (int i = 0; i < objectlist.Count; i++)
                {
                    s = objectlist[i].ToString() + "★";
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController: ClickPage:" + ex);
                obj.Add(" ★ ");

            }
            //通过调用RenderJSON来将数据传到前台
            RenderJSON(obj);

        }
        #endregion

        #region 分页和数据库交互的代码
        //分页和数据库交互的代码
        public List<object> GetRecShop(string pageID)
        {
            string s = "";
            List<object> obj = new List<object>();
            //分割开传入的数据
            string[] page = pageID.Split(',');
            //得到点击的页码
            int pagenum = Convert.ToInt32(page[0]);
            //得到categoryID
            int categoryID = Convert.ToInt32(page[2]);
            try
            {
                //通过调用RecShop来得到相应的数据
                IEnumerable<RecShop> c = RecShop(page[1], categoryID, pagenum);
                //通过循环将数据加到变量中并加载到OBJ中
                for (int i = 0; i < c.Count(); i++)
                {
                    //change the data type
                    RecShop sss = c.ElementAt(i);
                    s = sss.name + "★" + sss.shopID + "★" + sss.imageLocation + "★" + sss.description;
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController: GetRecShop:" + ex);
                obj.Add(" ★ ");

            }
            //返回OBJ
            return obj;
        }
        #endregion

        #region 得到具体页的数据
        //得到具体页的数据
        public List<object> GetRecShop(string cityID, int category, int page)
        {
            string s = "";
            List<object> obj = new List<object>();
            try
            {
                //调用RecShop来得到相应的数据
                IEnumerable<RecShop> c = RecShop(cityID, category, page);
                //通过循环来将数据加到变量中,并加载到OBJ中
                for (int i = 0; i < c.Count(); i++)
                {
                    //change the data type
                    RecShop sss = c.ElementAt(i);
                    s = sss.name + "|" + sss.shopID + "|" + sss.imageLocation + "|" + sss.description + "|" + sss.city + "|" + sss.latitude + "|" + sss.longitude;
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController: GetRecShop:" + ex);
                obj.Add(" |  | ");

            }

            return obj;
        }
        #endregion

        #region 计算页数
        //计算页数
        public List<object> GetRecShop(string cityID, int category)
        {
            int s = 0;
            List<object> obj = new List<object>();
            try
            {
                //通过调用RecShop来得到商户的总数
                IEnumerable<RecShop> c = RecShop(cityID, category);

                s = c.Count();

                obj.Add(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController: GetRecShop:" + ex);
                obj.Add("0");

            }
            //返回商户总数
            return obj;
        }
        #endregion

        #region Get all the recommend shop
        //Get all the recommend shop
        public IEnumerable<RecShop> RecShop(string id, int category)
        {
            IEnumerable<RecShop> c = null;
            int grade = 1;
            int shopCityID = Convert.ToInt32(id);

            try
            {
                //调用这个方法来得到商户的索引信息
                c = _recShop.getRecShop(category, shopCityID, grade);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:RecShop:" + ex);
            }
            //返回得到的信息
            return c;

        }
        #endregion

        #region Get all the recommended shop by page
        //Get all the recommended shop by page
        public IEnumerable<RecShop> RecShop(string id, int category, int page)
        {
            int recordPerPage = 5;
            int grade = 1;
            int pageInt = page;
            int shopCityID = Convert.ToInt32(id);

            IEnumerable<RecShop> c = null;
            try
            {
                //根据用户点击的页码书来查询出相应的数据
                c = _recShop.getRecShop(shopCityID, category, grade, recordPerPage, pageInt);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:RecShop:" + ex);
            }
            //返回查询出的数据
            return c;

        }
        #endregion

        #endregion

        #region 点击查询后返回到CityDetail页
        //点击查询后返回到CityDetail页
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult search(string search)
        {
            CityMasterViewData(1);
            return View("CityDetail");

        }
        #endregion

        #region 一段点击用的代码
        public void changeOption(string id)
        {
            string s = null;
            if (id == "0")
            {
                s = "This is the page initialize";
            }
            else if (id == "1")
            {
                s = "This is the click 'study abroad'";
            }
            else if (id == "2")
            {
                s = "This is the click 'play'";
            }
            else if (id == "3")
            {
                s = "This is the click 'bite and sup'";
            }
            else if (id == "4")
            {
                s = "This is the click 'pub up'";
            }
            else if (id == "5")
            {
                s = "This is the click 'shopping'";
            }
            else if (id == "6")
            {
                s = "This is the click 'traffic'";
            }
            List<object> objectlist = new List<object>();
            try
            {
                objectlist.Clear();
                objectlist.Add(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:RecShop:" + ex);
                objectlist.Clear();
                objectlist.Add("| | | | | ");
            }

            RenderJSON(objectlist);
        }
        #endregion

        #region 右边商户弹出页
        //右边商户弹出页
        public ActionResult ShopAbstract(string id)
        {
            int ShopID = Convert.ToInt32(id);
            string shopName = null;
            string shopID = null;

            try
            {
                //通过调用GetShopAbstract来得到相应的数据
                IEnumerable<ShopDetail> c = GetShopAbstract(id);
                ShopDetail r = c.First();
                //得到商户名
                shopName = r.value.ToString();
                //得到商户ID
                shopID = r.shopID.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:ShopAbstract" + ex);
                shopID = "";
                shopName = "";
            }

            ViewData["message"] = shopName;

            ViewData["ID"] = shopID;

            return View();
        }
        #endregion

        #region 得到商户所有信息的数据查询接口
        public IEnumerable<ShopDetail> GetShopAbstract(string id)
        {
            IEnumerable<ShopDetail> c = _shopDetails.getShopDetails(id);
            return c;
        }
        #endregion

        #region 得到城市具体信息

        //得到城市具体信息
        public void GetCityMessage(string id)
        {
            string cityID = id;
            List<object> obj = new List<object>();
            List<object> objList = new List<object>();
            string s = "";

            try
            {
                obj.Clear();
                objList.Clear();
                //通过调用getCityMessageList方法来得到此城市的具体信息
                objList = getCityMessageList(Convert.ToInt32(cityID));
                //通过循环将数据加到变量中并加载到OBJ中
                for (int i = 0; i < objList.Count; i++)
                {
                    s = objList[i].ToString() + "|";
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentary" + ex);
                obj.Add(" | ");
            }

            //调用RenderJSON来将数据返回到页面中
            RenderJSON(obj);

        }

        #endregion

        #region 通过查询得到城市具体信息

        public List<object> getCityMessageList(int cityID)
        {
            List<object> obj = new List<object>();

            try
            {
                //通过调用getCity来得到相应的数据
                IEnumerable<City> s = _city.getCity(cityID);
                //通过调用getCityInfo来得到相应的数据
                IEnumerable<CityInfo> ss = _city.getCityInfo(cityID);
                //通过循环来得到CityName和CountryID并将需要的数据加到变量中,再加载到OBJ中
                for (int i = 0; i < s.Count(); i++)
                {
                    City c = s.ElementAt(i);
                    CityInfo cc = ss.ElementAt(i);

                    string CityName = c.cityName;
                    string CountryID = c.countryID.ToString();
                    string objs = CityName + "|" + CountryID + "|" + c.cityNameEN + "|" + c.cityNameJP + "|" + cc.hotInfo;
                    obj.Add(objs);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentaryList" + ex);
                string o = " | | 尚无次城市信息";
                obj.Add(o);

            }
            //返回所有的数据给调用的地方
            return obj;
        }

        #endregion

        #region 点击查询以后在右边显示的东西
        //点击查询以后在右边显示的东西
        public void SearchClick(string id)
        {
            List<object> obj = new List<object>();
            //string s = "";
            List<object> objectlist = new List<object>();

            string CityID = "";
            string CategoryID = "";

            try
            {
                string[] subs = id.Split(',');
                //得到CityID
                CityID = subs[0];
                //得到CategoryID
                CategoryID = subs[1];

                //组合searchString,searchString为前台的第一个下拉框和第二个下拉框的文本
                string searchString = "0";
                //调用后台查询方法得到查询出的数据
                obj = getSearchMessage(searchString, Convert.ToInt32(CityID), Convert.ToInt32(CategoryID));
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentaryList" + ex);
                string o = "";
                obj.Add(o);
            }
            //调用RenderJSON来将数据返回到前台中
            RenderJSON(obj);
        }
        #endregion

        #region 通过调用数据库接口方法来得到相应的数据
        public List<object> getSearchMessage(string searchString, int CityID, int CategoryID)
        {
            List<object> obj = new List<object>();
            string s = "";
            List<object> objectlist = new List<object>();
            try
            {

                //通过调用doShopSearch来得到查询后的数据结果
                List<SearchKey> c = _shopSearch.doShopSearch(searchString, CityID, CategoryID);
                //取出数据结果在将其添加到OBJ中
                SearchKey rc = c.First();

                string searchID = rc.searchID.ToString();
                string count = rc.resultCount.ToString();

                s = searchID + "|" + count;
                obj.Add(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentaryList" + ex);
                string o = "";
                obj.Add(o);
            }
            //返回OBJ给调用的方法
            return obj;
        }
        #endregion

        #region 根据之前查出的SEARCHID等相关信息来进行分页查询
        //根据之前查出的SEARCHID等相关信息来进行分页查询
        public void searchButton(string id)
        {
            //方法数据初始化
            List<object> obj = new List<object>();
            //string s = "";
            List<object> objectlist = new List<object>();

            string CityID = "";
            string CategoryID = "";
            string searchString = "";


            try
            {
                //分割数据
                string[] subs = id.Split(',');
                //得到CITYID
                CityID = subs[0];
                //得到CATEGORYID
                CategoryID = subs[1];
                //得到searchString
                searchString = subs[2];
                //调用查询的后台方法来得到
                obj = getSearchMessage(searchString, Convert.ToInt32(CityID), Convert.ToInt32(CategoryID));
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentaryList" + ex);
                string o = "";
                obj.Add(o);
            }
            //通过调用RenderJSON方法来将数据返回到前台页面
            RenderJSON(obj);

        }
        #endregion

        #region 把查询出来的所有的查询的数据都返回到页面上
        //把查询出来的所有的查询的数据都返回到页面上
        public void initSearchTable(string id)
        {
            List<object> obj = new List<object>();
            string s = "";

            try
            {
                string[] searchString = id.Split(',');
                //得到serachID
                int serachID = Convert.ToInt32(searchString[0]);
                //得到resultCount
                int resultCount = Convert.ToInt32(searchString[1]);
                //固定一页显示5条记录
                int perPage = Convert.ToInt32(searchString[3]);
                //默认页码为第一页
                int pageNumber = Convert.ToInt32(searchString[2]);
                //通过调用getShopSearchResult方法来得到所需要的所有数据
                List<SearchResult> c = _shopSearch.getShopSearchResult(serachID, resultCount, perPage, pageNumber);
                //通过查询来得到各个数据
                for (int i = 0; i < c.Count; i++)
                {
                    SearchResult sr = c.ElementAt(i);
                    //得到商户名
                    string shopName = sr.name;
                    //得到城市ID
                    string cityID = sr.cityID.ToString();
                    //得到商户ID
                    string shopID = sr.shopID.ToString();
                    //得到商户具体信息
                    string description = sr.description;
                    //得到商户的经纬度
                    string lat = sr.latitude.ToString();
                    string lng = sr.longitude.ToString();
                    //得到商户的categoryID
                    int categoryID = (int)sr.categoryID;
                    //得到商户的图片路径
                    string imgLocation = sr.imageLocation;
                    //把所有数据加到变量中,然后加到OBJ中
                    s = shopName + "|" + cityID + "|" + shopID + "|" + description + "|" + lat + "|" + lng + "|" + categoryID + "|" + resultCount + "|" + imgLocation;
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentaryList" + ex);
                string o = "";
                obj.Add(o);
            }
            //通过调用RenderJSON来将数据返回到页面上
            RenderJSON(obj);
        }
        #endregion

        #region 评论页
        //评论页
        public ActionResult Commentary(string id)
        {
            //得到商户类型
            int categoryID = Convert.ToInt32(Request["CategoryID"].ToString());
            if (categoryID == 1)
            {
                ViewData["CategoryName"] = "餐饮";
                ViewData["categoryID"] = "1";
            }
            if (categoryID == 2)
            {
                ViewData["CategoryName"] = "住宿";
                ViewData["categoryID"] = "2";
            }
            if (categoryID == 3)
            {
                ViewData["CategoryName"] = "购物";
                ViewData["categoryID"] = "3";
            }
            if (categoryID == 4)
            {
                ViewData["CategoryName"] = "游玩";
                ViewData["categoryID"] = "4";
            }

            CityMasterViewData(1);
            return View();
        }
        #endregion

        #region 评论内容读取
        //评论内容读取

        public void readCommentary(string id)
        {
            List<object> obj = new List<object>();
            List<object> objList = new List<object>();
            string s = "";

            try
            {
                obj.Clear();
                objList.Clear();
                //通过调用readCommentaryList方法来得到评论内容
                objList = readCommentaryList(Convert.ToInt32(id));
                //通过循环来将数据加到变量中,然后加载到OBJ中
                for (int i = 0; i < objList.Count; i++)
                {
                    s = objList[i].ToString() + "|";
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentary" + ex);
                obj.Add(" | ");
            }
            //通过调用RenderJSON来将数据返回给前台页面
            RenderJSON(obj);

        }

        //通过读取后台数据的查询结果返回评论查询结果
        public List<object> readCommentaryList(int shopID)
        {
            List<object> obj = new List<object>();
            //通过调用getShopComment来得到所有评论信息
            IEnumerable<ShopComment> s = _shopComment.getShopComment(shopID);
            try
            {
                for (int i = 0; i < s.Count(); i++)
                {
                    ShopComment c = s.ElementAt(i);
                    //得到用户名
                    string UserName = c.userName;
                    //得到日期
                    string Date = c.createDate.ToString();
                    //得到评论信息
                    string Message = c.content.ToString();
                    //得到评论用户的IP
                    string IP = c.IP;
                    //将数据放到变量
                    string objs = UserName + "|" + Date + "|" + Message;
                    //将变量加到OBJ中
                    obj.Add(objs);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentaryList" + ex);
                string o = "尚没有评论";
                obj.Add(o);

            }
            //返回OBJ
            return obj;
        }

        #endregion

        #region 提交评论内容
        //提交评论内容
        public void CommentaryAction(string id)
        {
            //分割传入的数据
            string[] value = id.Split(',');

            List<object> obj = new List<object>();
            List<object> obj1 = new List<object>();
            //得到具体详细的信息
            string shopID = value[9];
            string subject = value[8];
            string content = value[4];
            string UserIP = System.Web.HttpContext.Current.Request.UserHostAddress;
            int parentCommentID = 0;
            int imageID = 0;
            int productID = 0;
            int commentType = 1;
            string username = value[10];
            //调用InsertMessage将数据插入到数据库
            Boolean b = InsertMessage(shopID, subject, content, UserIP, parentCommentID, imageID, productID, commentType, username);

            if (b == true)
            {
                string s = "OK";
                obj1.Add(s);
            }
            else
            {
                string s = "NO";
                obj1.Add(s);
            }
            //返回插入是否成功
            RenderJSON(obj1);
        }
        //插入到数据库的后台接口代码
        public Boolean InsertMessage(string shopID, string subject, string content, string UserIP, int parentCommentID, int imageID, int productID, int commentType, string username)
        {
            int c = _shopComment.insertShopComment(Convert.ToInt32(shopID), subject, content, username, UserIP, parentCommentID, commentType, imageID, productID);
            return true;
        }
        #endregion

        #region 转换城市数据代码开始
        //转换城市开始
        //得到城市
        public void changeCity(string id)
        {
            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            string s = "";
            try
            {
                objectlist.Clear();
                //调用City来得到城市信息
                objectlist = City(id);

                for (int i = 0; i < objectlist.Count; i++)
                {
                    s = s + objectlist[i].ToString() + ",";

                }
                obj.Add(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:changeCity" + ex);
                string o = " | ";
                obj.Add(o);

            }
            //调用RenderJSON来将数据返回到页面上
            RenderJSON(obj);


        }

        //得到地区
        public void changeProvince(string id)
        {
            List<object> obj = new List<object>();
            List<object> objectlist = new List<object>();
            string s = "";
            try
            {

                objectlist.Clear();
                //调用Province来得到一共有多少个地区
                objectlist = Province();
                for (int i = 0; i < objectlist.Count; i++)
                {
                    s = objectlist[i].ToString() + "|";
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:readCommentary" + ex);
                string o = " | ";
                obj.Add(o);

            }
            //将数据返回到前台页面上
            RenderJSON(obj);
        }

        //得到某地区的所以城市
        public List<object> City(string provinceID)
        {
            string s = "";
            //int testInt = 0;
            List<object> obj = new List<object>();
            try
            {


                //通过调用GetProvinceDetail来得到具体地区的相应城市
                IEnumerable<City> c = GetProvinceDetail(81, Convert.ToInt32(provinceID));
                for (int i = 0; i < c.Count(); i++)
                {
                    //change the data type
                    City sss = c.ElementAt(i);
                    if (sss.cityID == 3)
                    {
                        //testInt = 1;

                    }
                    else if (sss.cityID == 4)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 5)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 9)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 10)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 20)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 41)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 43)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 44)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 46)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 48)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 50)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 57)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 59)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 60)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 61)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 62)
                    {
                        //testInt = 1;
                    }
                    else if (sss.cityID == 63)
                    {
                        //testInt = 1;
                    }
                    else
                    {
                        s = sss.cityID + "|" + sss.cityName;
                        obj.Add(s);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:City" + ex);
                string o = " | ";
                obj.Add(o);

            }
            //将查询出的数据返回给调用的地方
            return obj;
        }

        //得到该国家在记录中的所有地区
        public IEnumerable<City> GetProvinceDetail(int CountryID, int ProvinceID)
        {
            IEnumerable<City> c = _city.getCity(CountryID, ProvinceID);
            return c;
        }

        //得到索引地区的记录
        public List<object> Province()
        {
            int CountryID = 81;
            string s = "";
            List<object> obj = new List<object>();
            try
            {
                //通过调用getProvince来得到所有的地区信息
                IEnumerable<Province> c = getProvince(CountryID);
                //通过循环来得到将所有的信息加载到变量和OBJ中
                for (int i = 0; i < c.Count(); i++)
                {
                    //change the data type
                    Province sss = c.ElementAt(i);
                    s = sss.provinceID + "|" + sss.provinceName;
                    obj.Add(s);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:Province" + ex);
                string o = " | ";
                obj.Add(o);

            }
            //返回OBJ给调用的地方
            return obj;
        }
        #endregion

        #region 获得城市默认经纬度
        //获得城市默认经纬度
        public void getCityInitLatLng(string id)
        {
            string cityID = id;
            List<object> obj = new List<object>();
            string s = "";
            //通过getCityinitLan来得到该城市的默认经纬度
            s = getCityinitLan(cityID);

            obj.Add(s);
            RenderJSON(obj);
        }


        //得到默认城市的经纬度
        public string getCityinitLan(string cityID)
        {
            //将现在所有的城市的默认的经纬度
            Hashtable CityinitLan = new Hashtable();
            CityinitLan.Add("1", "43.012531,141.333234");      //札幌
            CityinitLan.Add("2", "43.1432599,141.0367159");      //小樽
            CityinitLan.Add("4", "43.1432599,141.0367159");
            CityinitLan.Add("6", "43.9956698,144.2293245");
            CityinitLan.Add("7", "43.1045251,144.3244884");
            CityinitLan.Add("8", "41.7662461,140.7156392");      //函馆

            CityinitLan.Add("11", "37.8822135,139.057957");     //新潟
            CityinitLan.Add("12", "36.7740922,137.8866499");     //长野
            CityinitLan.Add("13", "35.4083254,138.8786291");     //山梨
            CityinitLan.Add("14", "36.5829562,137.446734");     //富山
            CityinitLan.Add("15", "36.5712853,136.6573075");     //石川
            CityinitLan.Add("16", "36.0558676,136.3542089");
            CityinitLan.Add("17", "35.3121708,138.9595031");     //静冈
            CityinitLan.Add("18", "35.0905771,136.8782433");
            CityinitLan.Add("19", "36.2570803,136.9054109");     //岐阜
            //CityinitLan.Add("20", "0004");     //青森
            CityinitLan.Add("21", "39.700139,140.730889");     //秋田
            CityinitLan.Add("22", "39.4515749,141.069751");
            CityinitLan.Add("23", "38.1765128,140.3084022");     //山形
            CityinitLan.Add("24", "38.2639068,140.8549878");     //宫城
            CityinitLan.Add("25", "37.5468168,140.1024668");     //福岛
            CityinitLan.Add("26", "35.69106,139.7067408");     //东京
            CityinitLan.Add("27", "35.4424246,139.6462862");     //神奈川
            CityinitLan.Add("28", "35.7848983,140.3227604");     //千叶
            CityinitLan.Add("29", "35.9027117,139.716196");
            CityinitLan.Add("30", "36.7680934,140.3547407");
            CityinitLan.Add("31", "36.7580403,139.5988494");
            CityinitLan.Add("32", "36.4982652,138.9303876");
            CityinitLan.Add("33", "34.6515342,135.5102378");     //大阪
            CityinitLan.Add("34", "35.0505685,135.7664316");     //京都
            CityinitLan.Add("35", "34.7007317,135.1899059");
            CityinitLan.Add("36", "34.6858733,135.8325921");     //奈良
            CityinitLan.Add("37", "34.1851701,135.1900269");     //和歌山
            CityinitLan.Add("38", "34.5745295,136.5269929");
            CityinitLan.Add("39", "34.9710668,135.94331");
            CityinitLan.Add("40", "34.3861281,132.4731688");     //广岛
            CityinitLan.Add("41", "34.6034423,133.7651923");     //山口
            // CityinitLan.Add("42", "0065");     //冈山
            //CityinitLan.Add("43", "0099");
            // CityinitLan.Add("44", "0099");
            CityinitLan.Add("45", "34.3526865,133.8261282");     //香川
            // CityinitLan.Add("46", "0084");     //德岛
            CityinitLan.Add("47", "33.9773144,133.0066943");
            // CityinitLan.Add("48", "0040");     //高知
            CityinitLan.Add("49", "33.5199899,130.5340224");     //福冈
            //CityinitLan.Add("50", "0099");
            CityinitLan.Add("51", "32.7341869,129.8701261");     //长崎
            CityinitLan.Add("52", "32.8057362,130.7055941");     //熊本
            CityinitLan.Add("53", "33.2361469,131.6115579");
            CityinitLan.Add("54", "31.8320015,131.4101203");     //宫崎
            CityinitLan.Add("55", "31.5951953,130.555677");     //鹿儿岛
            CityinitLan.Add("56", "26.215276,127.6813898");     //那霸
            CityinitLan.Add("57", "26.6102788,127.9909093");     //冲绳
            CityinitLan.Add("58", "26.6102788,127.9909093");     //冲绳
            CityinitLan.Add("59", "26.6102788,127.9909093");     //冲绳
            //CityinitLan.Add("60", "0111");     //宫古岛
            // CityinitLan.Add("61", "0099");
            //CityinitLan.Add("62", "0099");
            //CityinitLan.Add("63", "0099");
            object cityNum = CityinitLan[cityID];

            if (cityNum == null)
            {
                return null;
            }
            else
            {
                return cityNum.ToString();
            }

        }
        #endregion

        #region 获得城市详细页地图marker信息
        //获得城市详细页地图marker信息
        public void GetCityMarker(string id)
        {
            if (id == null) return;

            String location = id;
            List<object> obj = new List<object>();
            String[] loc = location.Split(',');

            if (loc.Length != 7)
                return;
            //得到数据的一些初始化信息
            double north = Convert.ToDouble(loc[0]);

            double south = Convert.ToDouble(loc[2]);

            string cityID = loc[4];
            int categoryID = Convert.ToInt32(loc[5]);
            int pageID = Convert.ToInt32(loc[6]);
            int recordPerPage = 5;
            int grade = 1;

            try
            {
                //通过调用getRecShop来得到商户的所有详细信息
                List<RecShop> objectlist = _recShop.getRecShop(Convert.ToInt32(cityID), categoryID, grade, recordPerPage, pageID);
                if (objectlist.Count != 0)
                {
                    string shopID = "";
                    string shopLogo = "";
                    string shopMessage = "";
                    string shopType = "";
                    double lat;
                    double lng;
                    double initlat = 0.00;
                    double initlng = 0.00;

                    foreach (RecShop r in objectlist)
                    {
                        //得到商户的经纬度
                        lat = Convert.ToDouble(r.latitude);
                        lng = Convert.ToDouble(r.longitude);
                        //判断,如果查询出的商户的经纬度为0的话则就对其经纬度进行初始化赋值
                        if (lat == 0.00 && lng == 0.00)
                        {
                            //通过调用getCityinitLan来得到城市的初始化经纬度
                            string initCityLan = getCityinitLan(cityID);
                            string[] lag = initCityLan.Split(',');
                            initlat = Convert.ToDouble(lag[0]);
                            initlng = Convert.ToDouble(lag[1]);
                        }

                        shopID = Convert.ToString(r.shopID);
                        shopLogo = r.imageLocation;
                        shopMessage = r.description;
                        //将数据加到变量和OBJ中
                        string result = lat.ToString() + "|" + lng.ToString() + "|" + shopID + "|" + shopLogo + "|" + shopMessage + "|" + shopType + "|" + initlat + "|" + initlng;
                        obj.Add(result);

                    }
                }
                else
                {
                    string o = "nothing";
                    obj.Add(o);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CityController:GetCityMarker" + ex);
                string o = "nothing";
                obj.Add(o);

            }
            //调用RenderJSON将数据返回到页面中
            RenderJSON(obj);
        }
        #endregion

        #region 商户信息页中的查询
        //商户信息页中的查询
        public void getTrademarkSearch(string id)
        {
            //分割相关的数据得到我们需要的CATEGORYID
            string[] ID = id.Split(',');
            //得到CATEGORYID
            string categoryID = ID[1];
            //利用SESSION做标志位
            Session["testTrademarkSearch"] = categoryID;
            List<object> obj = new List<object>();
            string s = "ok";
            obj.Add(s);

            RenderJSON(obj);
        }

        //商户信息页中的搜索
        public void getTrademarkSearchButton(string id)
        {
            //得到用户输入的字符串
            string searchString = id;
            //用于做标记的SESSION
            Session["searchButton"] = searchString;

            List<object> obj = new List<object>();
            string s = "ok";
            obj.Add(s);

            RenderJSON(obj);

        }
        #endregion
    }
}